<template>
<div class="app-header">
    <mt-header fixed title="网站名称">
        <span  slot="left" v-show="flag">
            <!-- 实现返回要监听路由地址 -->
            <mt-button icon="back" @click="goback">返回</mt-button>
      </span>
    </mt-header>
        <nav class="mui-bar mui-bar-tab">
            <router-link class="mui-tab-item-up " to="/home">
                <span class="mui-icon mui-icon-home"></span>
                <span class="mui-tab-label">首页</span>
            </router-link>
            <router-link class="mui-tab-item-up" to="/member">
                <span class="mui-icon mui-icon-contact"></span>
                <span class="mui-tab-label">会员</span>
            </router-link>
            <router-link class="mui-tab-item-up" to="/shopcar">
                <span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span class="mui-badge" id="badge">{{$store.getters.getCarCount}}</span></span>
                <span class="mui-tab-label">购物车</span>
            </router-link>
            <router-link class="mui-tab-item-up" to="/search">
                <span class="mui-icon mui-icon-search"></span>
                <span class="mui-tab-label">搜索</span>
            </router-link>
        </nav>
        <transition>
            <router-view></router-view>
        </transition>
        <div class="show_out" v-show="$store.state.loadingFlag">
            <img src="static/loading.gif">
        </div>
        <backtop></backtop>
</div>
</template>

<script>
    import backtop from './components/subcomponents/BackTop.vue'
export default{
    data(){
        return {
            // 默认是显示
            flag:true
        }
    },
    methods:{
        goback(){
            this.$router.back(-1)
        }
    },
    created(){
    },
    watch:{
        // 监听路由地址,当地址在首页时隐藏 返回 按钮
        "$route.path":function(){
            // 假如是跟路径就隐藏图标，否则显示
            this.flag=this.$route.path==='/home'?false:true

        }
    },
    components:{
        backtop
    }
}
</script>

<style lang="scss" scoped>

    .app-header{

        padding:50px 10px;
        .is-fixed{
        z-index: 2;
        }
    }
    .v-enter{
        opacity: 0;
        transform: translateX(100%);
    }
    .v-leave-to{
        opacity: 0;
        transform: translateX(-100%);
        position: absolute;
    }
    .v-enter-active,
    .v-leave-active{
        transition: all 0.5s ease;
    }
    // 解决无法切换的问题，修改元素的类名
    .mui-tab-item-up.mui-active{
    color: #007aff;
    }
    .mui-tab-item-up{
    display: table-cell;
    overflow: hidden;
    width: 1%;
    height: 50px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #929292;
    .mui-icon{
        top: 3px;
    width: 24px;
    height: 24px;
    padding-top: 0;
    padding-bottom: 0;
    }
    .mui-tab-label{
        font-size: 11px;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    }
}

.show_out{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background-color: rgba(0,0,0,.5);
    img{
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top:-62px;
        margin-left:-62px;
    }
}

</style>